import request from '@/utils/request'

export function getCompany() {
  return request({
    url: '/company/department'
  })
    .then(res => res.data.data.depts)
    .catch(() => [])
}
export function getCompanyDetails(id) {
  return request({
    url: '/company/' + id
  })
    .then(res => res.data.data)
    .catch(() => ({}))
}
// 权限列表
export function getPermissions() {
  return request({
    url: '/sys/permission'
  })
    .then(res => res.data.data)
    .catch(() => [])
}
// 角色权限
export function getRolePermissions(id) {
  return request({
    url: '/sys/role/' + id
  })
    .then(res => res.data.data)
    .catch(() => ({}))
}

// 角色权限分配
export function updateRolePermissions(id, permIds) {
  return request({
    url: '/sys/role/assignPrem',
    method: 'put',
    data: {
      id,
      permIds
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}
// 编辑更新角色
export function editorRole(params) {
  return request({
    url: '/sys/role/' + params.id,
    method: 'put',
    data: {
      ...params
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}
